//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.activiti.engine.impl.el;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.delegate.VariableScope;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.delegate.ExpressionGetInvocation;
import org.activiti.engine.impl.delegate.ExpressionSetInvocation;
import org.activiti.engine.impl.javax.el.ELContext;
import org.activiti.engine.impl.javax.el.ELException;
import org.activiti.engine.impl.javax.el.MethodNotFoundException;
import org.activiti.engine.impl.javax.el.PropertyNotFoundException;
import org.activiti.engine.impl.javax.el.ValueExpression;
import org.activiti.engine.impl.juel.AstEval;
import org.activiti.engine.impl.juel.AstMethod;
import org.activiti.engine.impl.juel.Node;
import org.activiti.engine.impl.juel.TreeValueExpression;

public class JuelExpression implements Expression {
    protected String expressionText;
    protected ValueExpression valueExpression;

    public JuelExpression(ValueExpression valueExpression, String expressionText) {
        this.valueExpression = valueExpression;
        this.expressionText = expressionText;
    }

    public Object getValue(VariableScope variableScope) {
        ELContext elContext = Context.getProcessEngineConfiguration().getExpressionManager().getElContext(variableScope);

        try {
            ExpressionGetInvocation invocation = new ExpressionGetInvocation(this.valueExpression, elContext);
            Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
            return invocation.getInvocationResult();
        } catch (PropertyNotFoundException var4) {
            throw new ActivitiException("Unknown property used in expression: " + this.expressionText, var4);
        } catch (MethodNotFoundException var5) {
            throw new ActivitiException("Unknown method used in expression: " + this.expressionText, var5);
        } catch (ELException var6) {
            throw new ActivitiException("Error while evaluating expression: " + this.expressionText, var6);
        } catch (Exception var7) {
            throw new ActivitiException("Error while evaluating expression: " + this.expressionText, var7);
        }
    }

    public void setValue(Object value, VariableScope variableScope) {
        ELContext elContext = Context.getProcessEngineConfiguration().getExpressionManager().getElContext(variableScope);

        try {
            ExpressionSetInvocation invocation = new ExpressionSetInvocation(this.valueExpression, elContext, value);
            Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
        } catch (Exception var5) {
            throw new ActivitiException("Error while evaluating expression: " + this.expressionText, var5);
        }
    }

    public String toString() {
        return this.valueExpression != null ? this.valueExpression.getExpressionString() : super.toString();
    }

    public String getExpressionText() {
        return this.expressionText;
    }

    public ValueExpression getValueExpression() {
        return valueExpression;
    }

    /**
     * 获取实体类名称
     * @return
     */
    public String getClassName(){
        return ((TreeValueExpression) valueExpression).getNode().getChild(0).getChild(0).getChild(0).toString();
    }

    /**
     * 获取方法名称
     * @return
     */
    public String getMethods(){
        return ((TreeValueExpression) valueExpression).getNode().getChild(0).getChild(0).toString().replace(".","");
    }

    /**
     * 获取参数
     * @return
     */
    public Node getParameter(){
        return ((TreeValueExpression) valueExpression).getNode().getChild(0).getChild(1);
    }

    //
}
